﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ProjectSemIII.Entity;
using ProjectSemIII.Process;

namespace ProjectSemIII
{
    public partial class Default : System.Web.UI.Page
    {
        private SurveyProcess svprocess;
        private Statistics statis;
        private List<Winer> lw;
        private Survey sv;
        protected void Page_Load(object sender, EventArgs e)
        {
            svprocess = new SurveyProcess();
            statis = new Statistics();
            lw = statis.getListNewWinner().OrderByDescending(o => o.Mark).ToList();
            if (lw.Count > 0)
            {
                sv = svprocess.getSurveyByID(lw[0].SurveyID);
                winnerone.Text = lw[0].Name;
                winnertwo.Text = lw[1].Name;
                winnerthree.Text = lw[2].Name;
                listWinner.Text = "The full list of <span style=\"color: rgb(189, 46, 18);\">" + sv.SurveyName + "</span> Survey winners is as follows:";
            }
            else
            {
                listWinner.Text = "No New Winner!";
            }
            if (Session["UserName"] == null)
            {
                sv = svprocess.getSurveyDefault(1);
                if (sv.SurveyName == null)
                {
                    surveyName.Text = "New Survey";
                }
                else
                {
                    surveyName.Text = sv.SurveyName;
                    surveyDetalt.Text = sv.SurveyDesc;
                    imageSurvey.ImageUrl = "/Images/Surveys/" + sv.SurveyImage;
                    playSurvey.NavigateUrl = "Survey.aspx?idsurvey=" + sv.SurveyID;
                }
            }
            else
            {
                sv = svprocess.getSurveyDefault(Convert.ToInt32(Session["Group"]));
                if (sv.SurveyName == null)
                {
                    surveyName.Text = "New Survey";
                }
                else
                {
                    surveyName.Text = sv.SurveyName;
                    surveyDetalt.Text = sv.SurveyDesc;
                    imageSurvey.ImageUrl = "/Images/Surveys/" + sv.SurveyImage;
                    playSurvey.NavigateUrl = "Survey.aspx?idsurvey=" + sv.SurveyID;
                }
            }
        }
    }
}